/**
 * 数据血缘分析专用Hook - 兼容层
 * 使用新的通用通知系统，保持向后兼容
 */

import { useCallback } from 'react';
import { useProgressNotification } from './useProgressNotification';

// 数据血缘分析专用Hook - 兼容层，使用新的通用系统
export const useDataLineageProgress = () => {
  // 使用新的通用系统
  const progressHook = useProgressNotification();

  const startLineageAnalysis = useCallback((dataSource: string) => {
    return progressHook.start({
      type: 'progress',
      title: '数据血缘解析',
      description: `正在分析 ${dataSource} 的数据血缘关系...`,
      category: 'data-lineage',
      source: dataSource,
      config: {
        persistent: true,
        autoClose: false,
        showProgress: true,
        showTimestamp: true,
        priority: 6,
      },
    });
  }, [progressHook]);

  const updateAnalysisProgress = useCallback((
    id: string,
    progress: number,
    stage: string,
    currentItem?: string,
    statistics?: Record<string, any>
  ) => {
    progressHook.updateProgress(id, {
      progress: progress, // 直接传递数字进度值
      currentStage: stage,
      currentItem,
      statistics,
    });
  }, [progressHook]);

  const completeAnalysis = useCallback((
    id: string,
    success: boolean,
    summary?: string,
    statistics?: Record<string, any>
  ) => {
    progressHook.complete(id, {
      success,
      summary,
      statistics,
    });
  }, [progressHook]);

  const pauseAnalysis = useCallback((id: string) => {
    progressHook.pause(id);
  }, [progressHook]);

  const resumeAnalysis = useCallback((id: string) => {
    progressHook.resume(id);
  }, [progressHook]);

  const cancelAnalysis = useCallback((id: string) => {
    progressHook.cancel(id);
  }, [progressHook]);

  const failAnalysis = useCallback((
    id: string,
    error: string,
    details?: string
  ) => {
    progressHook.fail(id, {
      message: error,
      details,
    });
  }, [progressHook]);

  return {
    startLineageAnalysis,
    updateAnalysisProgress,
    completeAnalysis,
    pauseAnalysis,
    resumeAnalysis,
    cancelAnalysis,
    failAnalysis,
  };
};
